package GUI;
/**
 * In the process of allocating a teacher in the middle of the semester 
 * the administration user select which teacher requested a substitution
 */

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;

public class SubTeacherSelect extends JPanel {
	private JLabel label = null;
	private JLabel label_1 = null;
	private JComboBox cBSelSubsTeacher = null;
	private JButton btnNext = null;
	private String selSubsTeacher=null;
	private String selStudyUnit=null;
	
	public Login myLoginFrame = null;
	public UserAdmin user=null;
	public AdminMainMenu amn=null;	
	private SubTeacherSelCrs teacherAllocScrn_2 = null;
	private String teacherDetails = null;
	
	private String [] temp = null;
	
	public JComboBox getSelSubsTeacherCb(AdminMainMenu amn)
	{
		Vector<String> data = new Vector<String>();
		for(int i=0;i<amn.user.DataForEx.Teachers.size();i++)
		{
		data.add(amn.user.DataForEx.Teachers.get(i).FirstName+" "+amn.user.DataForEx.Teachers.get(i).LastName+" "+amn.user.DataForEx.Teachers.get(i).StudUnit+" "+amn.user.DataForEx.Teachers.get(i).tid);
		}
		if(cBSelSubsTeacher==null)
		{
		 cBSelSubsTeacher = new JComboBox(data);
		 cBSelSubsTeacher.addActionListener(new ActionListener() {
		 	public void actionPerformed(ActionEvent arg0) {
		 		 teacherDetails=cBSelSubsTeacher.getSelectedItem().toString();
		 		String s=teacherDetails;
		 		 temp=s.split(" ");
		 		//selSubsTeacher=temp[2];
		 		selStudyUnit=temp[2];
		 		
		 		System.out.println(teacherDetails);
		 		System.out.println(selStudyUnit);
		 	//	System.out.println(selSubsTeacher);
		 		
		 			 		
		 		
		 	}
		 });
		 cBSelSubsTeacher.setBounds(256, 77, 178, 20);
		}
		return cBSelSubsTeacher;
	}
	
	
	public JButton getBtnNext(final AdminMainMenu amn)
	{
		if(btnNext==null)
		{
		btnNext = new JButton("Next");
		btnNext.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				teacherAllocScrn_2 = null;
				amn.user.DataForEx.setSelSubsTeacher(teacherDetails);
				amn.user.DataForEx.setSelStudyUnit(selStudyUnit);
				teacherAllocScrn_2 = amn.getTeacherAllocScrn_2();
				amn.setContentPane(teacherAllocScrn_2);
				
				
			}
		});
		btnNext.setBounds(517, 315, 89, 23);
		}
		
		return  btnNext ;
		
	}
	
	public void initialize(AdminMainMenu amn)
	{
		setLayout(null);
		
		 label = new JLabel("Exceptional request - Teacher allocation from class");
		label.setBounds(242, 11, 243, 14);
		add(label);
		
		label_1 = new JLabel("Select substitutable teacher:");
		label_1.setBounds(64, 80, 138, 14);
		add(label_1);
		add(getSelSubsTeacherCb(amn));
		add(getBtnNext(amn));
		
	}
	
	
	
	
	
	public SubTeacherSelect(AdminMainMenu amn) {
		super();
		initialize(amn);
		
	}
}
